<?php
session_start ();
include '../base/validateAdminLogin.php';
include '../class/MMysql.php';

if (isset($_COOKIE["user_id"]))
    $user_id= $_COOKIE["user_id"];

$mysql = new MMysql();
$user = $mysql
    ->where(array('user_id'=>$user_id,"del_flag"=>0))
    ->select('user');


$error="";
if (isset ( $_POST ['user_first_name'] )) {
    $user_first_name = $_POST ['user_first_name'];
    $user_last_name = $_POST ['user_last_name'];
    $user_email = $_POST ['user_email'];
    $user_tel = $_POST ['user_tel'];
//    $user_password = $_POST ['user_password'];

    if ($user_first_name == "" || $user_last_name == "" || $user_email == "" || $user_tel == "") {
        $error = "<span class='error'>user_info is not null</span>";
    } else {
        $first_name=$user_first_name;
        $last_name=$user_last_name;
        $email=$user_email;
        $tel=$user_tel;

        $mysql = new MMysql();
        $res = $mysql
            ->update('user',array('user_first_name'=>$first_name,'user_last_name'=>$last_name,"user_email"=>$email,"user_tel"=>$tel));
        if ($res>0) {
            echo "<script type=text/javascript>alert('edit success');window.location.href='settings_page_show.php';</script>";
        } else {

           // $error = "<span class='error'>edit is wrong！</span>";
        }
    }
}
?>

<?php
  include '../base/layout.php';
?>

<body>

<?php
 include '../base/header.php';
?>

<section style="width: 100%;">

    <?php
    include '../base/sidemenu.php';
    ?>

    <aside class="content">

        <div style="margin-top: 30px;margin-left: 100px;">
                 <span style="font-size: 30px;">
                        Settings
                 </span>
        </div>

        <div style="margin-top: 20px;margin-left: 100px;">
                <span style="font-size: 20px;color: rgb(154,154,154);">
                       Administrator Name
                </span>
        </div>
        <form action="settings_page_edit.php" method="post">

        <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                    First name
                </span>
            <?php
            if (isset($_COOKIE["user_first_name"]))
                $user_first_name= $_COOKIE["user_first_name"];
            echo '<input class="user_info_input" name="user_first_name" type="text" value="'.$user[0]['user_first_name'].'">'
            ?>

        </div>

        <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                    Last name
                </span>
            <?php
            if (isset($_COOKIE["user_last_name"]))
                $user_last_name= $_COOKIE["user_last_name"];
            echo '<input class="user_info_input" name="user_last_name" type="text" value="'.$user[0]['user_last_name'].'">'
            ?>

        </div>

        <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                    Email
                </span>
            <?php
            if (isset($_COOKIE["user_email"]))
                $user_email= $_COOKIE["user_email"];
            echo '<input class="user_info_input" name="user_email" type="text" value="'.$user[0]['user_email'].'">'
            ?>

        </div>

        <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                    Tel
                </span>
            <?php
            if (isset($_COOKIE["user_tel"]))
                $user_tel= $_COOKIE["user_tel"];
            echo '<input class="user_info_input" name="user_tel" type="text" value="'.$user[0]['user_tel'].'">'
            ?>

        </div>


        <div style="margin-top: 20px;margin-left: 100px;">

            <input class="btn" value="Confirm" type="submit" style="background-color: #2B2B2B;color:white;width: 100px;" />
            <?php
              echo $error;
            ?>
        </div>

        </form>

        <div style="margin-top: 60px;margin-left: 100px;">
                <span style="position: relative;line-height: 34px;font-size:20px;color: rgb(152,152,152);display: block;">
                    change my password
                </span>

            <input onclick="topassword()" type="text" class="form-control" style="margin-top: 10px;width: 400px;"
                   placeholder="click here to change my password">
        </div>

    </aside>

</section>

</body>
</html>

<script>
    function topassword() {

        window.location.href='settings_page_password.php';
    }
</script>

